//============================================================================
// Name        : get_cmd_result.cpp
// Author      : Janeyre
// Version     :
// Copyright   : BNRC
// Description : Hello World in C, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>

using namespace std;
string getCurrentPath();
int main(void)
{
	cout << "current path = " << getCurrentPath();
}

string getCurrentPath()
{
	FILE *ptr;
	char buff[256];
	string path = "";
	if ((ptr = popen("whereis java", "r")) != NULL)
	{
		while (fgets(buff, 256, ptr) != NULL)
		{
			buff[strlen(buff)] = '\0';
			path += buff;
		}
	}
	pclose(ptr);

	return path;
}
